package docsim;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;

public class DocumentPair implements WritableComparable{
	int doc1;
	int doc2;

	public void set(int d1, int d2) {
		doc1 = d1;
		doc2 = d2;
	}

	@Override
	public void readFields(DataInput arg0) throws IOException {
		doc1 = arg0.readInt();
		doc2 = arg0.readInt();
	}

	@Override
	public void write(DataOutput arg0) throws IOException {
		arg0.writeInt(doc1);
		arg0.writeInt(doc2);
	}

	@Override
	public int hashCode() {
		return (doc1 ^ doc2);
	}
	
	@Override
	public boolean equals(Object obj) {
		return ((((DocumentPair)obj).doc1 == doc1) && (((DocumentPair)obj).doc2 == doc2)); 
	}
	
	@Override
	public int compareTo(Object o) {
		if(((DocumentPair)o).doc1 != doc1)
		{
			return (((DocumentPair)o).doc1 - doc1); 
		}
		else
		{
			return (((DocumentPair)o).doc2 - doc2);
		}
	}
}
